<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>临时调试</title>
</head>
<body>


<img id="sky" src="./sky1.png" style="width: 300px;" />
<button id="change">按钮</button>


<script>

// 图片切换
 function changeImage(callback) {
            
            const img = document.getElementById('sky');
            if (!img) {
                console.error("错误：找不到ID为'sky'的图片元素");
                return;
            }
            
            const newSrc = callback(img.src);
            console.log("正在从", img.src, "切换到", newSrc);
            img.src = newSrc + '?t=' + Date.now(); // 添加时间戳防止缓存
        }
        // 绑定按钮点击事件,一定要有触发机制
        document.getElementById('change').addEventListener('click', () => {
            changeImage((currentSrc) => {
                return currentSrc.includes('sky1.png') 
                    ? './sky2.png' 
                    : './sky1,png';
            });
        });
 </script> 
   

    

</body>
</html>